package com.fulu.game.bi.service.impl.value;

import com.fulu.game.bi.common.util.csv.CsvExportUtil;
import com.fulu.game.bi.common.util.csv.Mapper;
import com.fulu.game.bi.common.util.csv.Querier;
import com.fulu.game.bi.entity.bo.channel.ValueAddGiftConsumeListBO;
import com.fulu.game.bi.entity.bo.channel.ValueAddUserConsumeListBO;
import com.fulu.game.bi.entity.enums.QueryTypeStatusEnum;
import com.fulu.game.bi.entity.enums.UserConsumeEnum;
import com.fulu.game.bi.entity.vo.value.ValueAddGiftConsumerListVO;
import com.fulu.game.bi.entity.vo.value.ValueAddUserConsumerListVO;
import com.fulu.game.bi.entity.vo.value.ValueAddUserConsumerRankListVO;
import com.fulu.game.bi.hbase.HBaseValueAddGiftConsumeStatDAO;
import com.fulu.game.bi.hbase.HBaseValueAddUserConsumeStatDAO;
import com.fulu.game.bi.redis.service.value.ValueAddGiftConsumeService;
import com.fulu.game.bi.redis.service.value.ValueAddUserConsumeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ValueAddGiftConsumeServiceImpl extends BaseValueService implements ValueAddGiftConsumeService {
    @Autowired
    private HBaseValueAddGiftConsumeStatDAO hBaseValueAddGiftConsumeStatDAO;

    @Override
    public PageInfo<ValueAddGiftConsumerListVO> list(ValueAddGiftConsumeListBO listBO) {
        listBO.setTableName(valueAddGiftConsumeStatMap.get(listBO.getQueryType()));
        listBO.setPageNum((listBO.getPageNum() - 1) * listBO.getPageSize());
        List<ValueAddGiftConsumerListVO> list = hBaseValueAddGiftConsumeStatDAO.list(listBO);
        Integer count = hBaseValueAddGiftConsumeStatDAO.count(listBO);
        list = list.stream().map(map -> {
            map.setQueryType(listBO.getQueryType());
            return map;
        }).collect(Collectors.toList());
        PageInfo<ValueAddGiftConsumerListVO> pageInfo = new PageInfo<>(list);
        pageInfo.setTotal(count == null ? 0 : count);
        return pageInfo;
    }

    @Override
    public void export(ValueAddGiftConsumeListBO bo) {
        String fileName = "礼物消费";
        LinkedHashMap<String, Mapper<ValueAddGiftConsumerListVO>> map = new LinkedHashMap<>();
        QueryTypeStatusEnum anEnum = QueryTypeStatusEnum.getEnum(bo.getQueryType());
        switch (anEnum) {
            case DAY:
                map.put("日期", v -> v.getStartDate());
                break;
            default:
                map.put("日期", v -> v.getStartDate() + "-" + v.getEndDate());
                break;
        }
        map.put("礼物ID", v -> v.getGiftId() + "");
        map.put("礼物名称", v -> v.getGiftName() + "");
        map.put("消费人数", v -> v.getConsumeUserNum() + "");
        map.put("消费次数", v -> v.getConsumeNum() + "");
        map.put("消费数量", v -> v.getAmount() + "");
        map.put("消费金额", v -> v.getVirtualMoneyAll().toString());
        map.put("魅力值", v -> v.getCharmMoneyAll().toString());
        Querier querier = (num) -> list(bo);
        CsvExportUtil.export(100, fileName, map, querier);
    }

    @Override
    public List<ValueAddGiftConsumerListVO> lineList(ValueAddGiftConsumeListBO listBO) {
        listBO.setTableName(valueAddGiftConsumeStatMap.get(listBO.getQueryType()));
        listBO.setPageNum((listBO.getPageNum() - 1) * listBO.getPageSize());
        List<ValueAddGiftConsumerListVO> list = hBaseValueAddGiftConsumeStatDAO.lineList(listBO);
        return list.stream().map(map -> {
            map.setQueryType(listBO.getQueryType());
            return map;
        }).collect(Collectors.toList());
    }
}
